﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TraderClient.Models;
using TraderClient.Logic.QuotationsCenter;
using TraderClient.Logic.TradeCenter;

namespace TraderClient.Logic.PolicyCenter
{
    /// <summary>
    /// 测试策略类
    /// </summary>
    class TestPolicy
    {
        /// <summary>
        /// 策略名称
        /// </summary>
        private const string policyName = "test";

        /// <summary>
        /// 行情接口对象
        /// </summary>
        private QuoteManager quotemanager;

        /// <summary>
        /// 交易接口对象
        /// </summary>
        private TradeManager tradeManager;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="paramQuoteManager">行情接口对象</param>
        /// <param name="paramTradeManager">交易接口对象</param>
        public TestPolicy(QuoteManager paramQuoteManager, TradeManager paramTradeManager)
        {
            quotemanager = paramQuoteManager;
            tradeManager = paramTradeManager;

            quotemanager.KLineOpen += OnKLineOpen;
            quotemanager.KLinePriceChange += OnKLinePriceChange;
        }

        //K线新开事件
        void OnKLineOpen(KLineSeries series)
        {
            if (series.Level == 1 && series.Unit == KLineUnit.Minutes)
            {
                KLine penult = series.PenultKLine;

                if (penult != null && (penult.Close > penult.Open))
                {
                    tradeManager.Buy(series.Market, policyName, series.Code, penult.Close, 1);
                    
                }
            }
        }

        //K线价格更新事件
        void OnKLinePriceChange(KLineSeries series)
        {

        }
    }
}
